﻿using System;
using System.Collections.Generic;
using System.Text;
using DataLayer.ObjectLists;
using DataLayer.Objects;
using Developex.DatabaseWrapper;

namespace TestProject
{
	class Program
	{
		static void Main(string[] args)
		{
			using (Connection conn = ConnectionCreator.Create())
			{
				SiteUser user = new SiteUser();
				user.Name = "name";
				if (!user.Exists(conn))
				{
					Console.WriteLine("Creating random users..");
					user.Insert(conn);
					Random rand = new Random();
					for (int i = 0; i < 100; i++)
					{

						user.Name = "user" + i;
						user.Age = rand.Next(20);
						user.Insert(conn);
					}
				}
				UsersList list1 = new UsersList();
				list1.GetUsers(conn, null, 21);
				Console.WriteLine("Users with age = 21:");
				foreach (SiteUser u in list1.Items)
				{
					Console.WriteLine(u.Name + ", " + u.Age);
				}

				UsersList list2 = new UsersList();
				list2.GetUsers(conn, "2", null);
				Console.WriteLine("Users with with name contains '2':");
				foreach (SiteUser u in list2.Items)
				{
					Console.WriteLine(u.Name + ", " + u.Age);
				}
			}
		}
	}
}
